package com.example.controller;

import com.example.pojo.Response;
import com.example.pojo.Spot;
import com.example.service.SpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spot")
public class SpotController {
    @Autowired
    private SpotService spotService;

    @GetMapping("/{id}")
    public Response<Spot> getSpotDetail(@PathVariable Integer id) {
        Spot spot = spotService.getSpotById(id);
        if (spot != null) {
            return Response.success(spot);
        } else {
            return Response.fail("景区不存在");
        }
    }

    @GetMapping("/list")
    public Response<List<Spot>> getSpotList() {
        List<Spot> spotList = spotService.getSpotList();
        if (spotList != null) {
            return Response.success(spotList);
        } else {
            return Response.fail("景区不存在");
        }
    }



}
